﻿
using System;
using System.Diagnostics;


namespace CrazyMan.TM.Interface.Domain
{
    /// <summary>
    /// Represents a betting interval.
    /// </summary>
    [DebuggerDisplay("Duration {Duration}; Blinds {SmallBlind}/{BigBlind}; Ante {Ante}")]
    public class BettingInterval : Interval
    {
        private int _ante;
        private int _bigBlind;
        private int _smallBlind;

        /// <summary>
        /// Creates a new betting interval.
        /// </summary>
        public BettingInterval()
            : base()
        { }

        /// <summary>
        /// Creates a new betting interval of a specified duration.
        /// </summary>
        /// <param name="duration">The duration of the betting interval.</param>
        public BettingInterval(int duration)
            : base(duration)
        {
        }

        /// <summary>
        /// Creates a new betting interval of a specified duration, with betting requirements.
        /// </summary>
        /// <param name="duration">The duration of the betting interval.</param>
        /// <param name="smallBlind">The cost of the small blind.</param>
        /// <param name="bigBlind">The cost of the big blind.</param>
        public BettingInterval(int duration, int smallBlind, int bigBlind)
            : this(duration, smallBlind, bigBlind, 0)
        {
        }

        /// <summary>
        /// Creates a new betting interval of a specified duration, with betting requirements.
        /// </summary>
        /// <param name="duration">The duration of the betting interval.</param>
        /// <param name="smallBlind">The cost of the small blind.</param>
        /// <param name="bigBlind">The cost of the big blind.</param>
        /// <param name="ante">The cost of the ante.</param>
        public BettingInterval(int duration, int smallBlind, int bigBlind, int ante)
            : base(duration)
        {
            ValidateBettingValue(smallBlind);
            ValidateBettingValue(bigBlind);
            ValidateBettingValue(ante);

            _smallBlind = smallBlind;
            _bigBlind = bigBlind;
            _ante = ante;
        }

        /// <summary>
        /// Gets and sets the ante during the betting schedule.
        /// </summary>
        public int Ante
        {
            get { return _ante; }
            set
            {
                ValidateBettingValue(value);
                _ante = value;
            }
        }

        /// <summary>
        /// Gets and sets the big blind during the betting interval.
        /// </summary>
        public int BigBlind
        {
            get { return _bigBlind; }
            set
            {
                ValidateBettingValue(value);
                _bigBlind = value;
            }
        }

        /// <summary>
        /// Gets and sets the small blind during the betting interval.
        /// </summary>
        public int SmallBlind
        {
            get { return _smallBlind; }
            set
            {
                ValidateBettingValue(value);
                _smallBlind = value; 
            }
        }

        /// <summary>
        /// Validates that the betting item is legal.
        /// </summary>
        /// <param name="item">The betting item to be validated.</param>
        protected void ValidateBettingValue(int value)
        {
            if (value < 0)
                throw new ArgumentOutOfRangeException("value", "A betting value can not be negative.");
        }

    }
}
